//
//  common.cpp
//  ampcontroller
//
//  Created by Developer on 20/01/2014.
//  Copyright (c) 2014 Maestun Abidjan. All rights reserved.
//

#include "common.h"

SPotDescriptor      gPots[MAX_INPUT_POTS];


#if defined(ORANGE_OR15)
    const char * INPUT_NAMES[MAX_INPUT_POTS]            = {"VOLUME",    "TREBLE",   "MID",      "BASS",     "GAIN"  };
    const bool INPUT_IS_DUAL[MAX_INPUT_POTS]            = {0,           0,          0,          0,          1       };
    const EPotType INPUT_TYPE[MAX_INPUT_POTS]           = {EPotLog,     EPotLin,    EPotLin,    EPotLog,    EPotLog };
    const unsigned long INPUT_OHM[MAX_INPUT_POTS]       = {1 * MEGA,    250 * KILO, 25 * KILO,  500 * KILO, 1 * MEGA};
    const unsigned long OUTPUT_OHM[MAX_INPUT_POTS]      = {1 * MEGA,    1 * MEGA,   100 * KILO, 1 * MEGA,   1 * MEGA};
    const unsigned char INPUT_ADDRESS[MAX_INPUT_POTS]   = {A0,          A1,         A2,         A3,         A4      };
    const unsigned char OUTPUT_ADDRESS[MAX_INPUT_POTS]  = {0x2c,        0x2d,       D2,         D3,         D4      };
#elif defined(VOX_AC15)
    const char * INPUT_NAMES[MAX_INPUT_POTS]    = {"NORMAL VOL","BOOST VOL","BASS",     "TREBLE",   "TR SPEED", "TR DEPTH", "REVERB",   "MASTER"    };
    const bool INPUT_IS_DUAL[MAX_INPUT_POTS]    = {0,           0,          0,          0,          0,          0,          0,          0           };
    const EPotType INPUT_TYPE[MAX_INPUT_POTS]   = {EPotLog,     EPotLog,    EPotLog,    EPotLog,    EPotRLog,   EPotLin,    EPotLin,    EPotLog     };
    const unsigned long INPUT_OHM[MAX_INPUT_POTS]         = {500 * KILO,  500 * KILO, 1 * MEGA,   1 * MEGA,   1 * MEGA,   500 * KILO, 100 * KILO, 500 * KILO  };
    const unsigned long OUTPUT_OHM[MAX_INPUT_POTS]        = {1 * MEGA,    1 * MEGA,   1 * MEGA,   1 * MEGA,   1 * MEGA,   1 * MEGA,   100 * KILO, 1 * MEGA    };
    const unsigned char INPUT_ADDRESS[MAX_INPUT_POTS]     = {A0,          A1,         A2,         A3,         A4,         A5,         A6,         A7          };
    const unsigned char OUTPUT_ADDRESS[MAX_INPUT_POTS]    = {0x2c,        0x2d,       D2,         D3,         D4,         D5,         D6,         D7          };
#elif
#endif



void init_pot_data() {
    
    Serial.println("init_pot_data");
    
    // create pot descriptors and fill
    for(int i = 0; i < MAX_INPUT_POTS; i++) {
        
        gPots[i].name = INPUT_NAMES[i];
        gPots[i].dual = INPUT_IS_DUAL[i];
        gPots[i].type = INPUT_TYPE[i];
        gPots[i].inputvalue = INPUT_OHM[i];
        gPots[i].inputaddress = INPUT_ADDRESS[i];
        gPots[i].outputvalue = OUTPUT_OHM[i];
        gPots[i].outputaddress = OUTPUT_ADDRESS[i];
        gPots[i].currentstep = -1;
        
        char * imult = "R";
        unsigned long ivalue = gPots[i].inputvalue;
        if(ivalue >= MEGA) {
            ivalue /= MEGA;
            imult = "M";
        }
        else if(ivalue >= KILO) {
            ivalue /= KILO;
            imult = "K";
        }
        char * omult = "R";
        unsigned long ovalue = gPots[i].outputvalue;
        if(ovalue >= MEGA) {
            ovalue /= MEGA;
            omult = "M";
        }
        else if(ovalue >= KILO) {
            ovalue /= KILO;
            omult = "K";
        }
        
        Serial.print("init_pot ");
        Serial.print(i, DEC);
        Serial.print(" (");
        Serial.print(gPots[i].name);
        Serial.print(gPots[i].dual ? " DUAL " : " ");
        Serial.print(gPots[i].type == EPotLog ? "LOG" : "LIN");
        
        Serial.println(") :");
        Serial.print("ival: ");
        Serial.print(ivalue, DEC);
        Serial.print(imult);
        Serial.print(" - iaddr: ");
        Serial.print(gPots[i].inputaddress, DEC);
        Serial.print(" - oval: ");
        Serial.print(ovalue, DEC);
        Serial.print(omult);
        Serial.print(" - oaddr: ");
        Serial.println(gPots[i].outputaddress, HEX);
        Serial.println("");
    }
}

